package com.mybatispluslambda.cglib.proxy.demo;

import lombok.extern.slf4j.Slf4j;
import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;
import java.util.Arrays;

@Slf4j
public class HelloConcrete {

    public String sayHello(String str) {
        return "HelloConcrete: " + str;
    }

    public static class MyMethodInterceptor implements MethodInterceptor {
        @Override
        public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
            log.info("you said :" + Arrays.toString(args));
            return proxy.invokeSuper(obj, args);
        }
    }

    public static void main(String[] args) {
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(HelloConcrete.class);
        enhancer.setCallback(new MyMethodInterceptor());

        HelloConcrete concrete = (HelloConcrete) enhancer.create();
        System.out.println(concrete.equals("ss"));
    }

}